#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QAxObject>
#include <QDebug>
#include <QDir>
#include <QMediaPlaylist>

void info(QAxBase *obj)
{
    qDebug() << "==================";

    qDebug() << obj->verbs();

    qDebug() << obj->propertyBag();

    QString doc = "<div>" + obj->generateDocumentation() + "</div>";
    doc = doc.replace(QRegExp("\n"), "");

    qDebug() << doc;
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
      , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 获取控件支持的方法
    QStringList methods = ui->axWidget->verbs();

    // 获取控件的文档信息
    QString docu = ui->axWidget->generateDocumentation();

    qDebug() << methods;
    //    qDebug() << docu;

    qDebug() << ui->axWidget->doVerb("system");
    qDebug() << ui->axWidget->property("objectName");
    //qDebug() << ui->axWidget->dynamicCall("launchURL(QString)",
    //                                    R"(D:\Backup\Downloads\菊次郎的夏天.mp3)");

    qDebug() << ui->axWidget->setProperty("uiMode", "full");          // 设置界面模式
    qDebug() << ui->axWidget->setProperty("enableContextMenu", true); // 启用右键菜单
    qDebug() << QDir::toNativeSeparators(R"(D:\Backup\Downloads\菊次郎的夏天.mp3)");
    qDebug() << ui->axWidget->setProperty("URL",
                                          QDir::toNativeSeparators(
                                              R"(D:\Backup\Downloads\菊次郎的夏天.mp3)"));

    //    qDebug() << ui->axWidget->dynamicCall("launchURL(QString)",
    //                                          QDir::toNativeSeparators(
    //                                              R"(D:\Backup\Downloads\菊次郎的夏天.mp3)"));

    qDebug() << ui->axWidget->property("mediaCollection");
    qDebug() << ui->axWidget->property("control");

    qDebug() << ui->axWidget->property("currentPlaylist");

    qDebug() << ui->axWidget->property("fullScreen");

    qDebug() << ui->axWidget->propertyBag();

    qDebug() << ui->axWidget->dynamicPropertyNames();

    qDebug() << ui->axWidget->setProperty("enableErrorDialogs", true);

    qDebug() << ui->axWidget->setProperty("baseURL", R"(D:\Backup\Downloads)");

    qDebug() << ui->axWidget->setProperty("playlist", (size_t) new QMediaPlaylist(this));

    qDebug() << ui->axWidget->setProperty("controls.pause()", 0);

    qDebug() << ui->axWidget->property("windowFilePath");

    qDebug() << ui->axWidget->property("isActiveWindow");

    qDebug() << ui->axWidget->property("versionInfo");

    //    qDebug() << ui->axWidget->property("currentMedia.name");

    qDebug() << ui->axWidget->property("currentMedia");

    qDebug() << ui->axWidget->querySubObject("currentMedia");

    QAxObject *playlist = ui->axWidget->querySubObject("currentPlaylist");

    qDebug() << playlist->verbs();

    qDebug() << playlist->propertyBag();

    qDebug() << playlist->dynamicPropertyNames();

    qDebug() << playlist->setProperty("name", "demo123");

    //    info(ui->axWidget);

    info(playlist);

    //    qDebug() << ui->axWidget->dynamicCall("GetSignalList()");
    QAxObject *controls = ui->axWidget->querySubObject("controls");
    controls->dynamicCall("stop()"); //调用成员函数
    info(controls);

    int a = 0;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initConnect() {}
